package org.jeecg.common.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileSplitUtil {

    public static void fileSplit(){
        try {
            File file = new File("记事.txt");
            FileInputStream fis = new FileInputStream(file);

            int fileSize = (int) file.length(); // 获取大文件的大小
            int chunkSize = 1024; // 每个小文件的大小为1KB
            int numChunks = (int) Math.ceil((double) fileSize / chunkSize); // 计算需要切割的小文件数量

            for (int i = 0; i < numChunks; i++) {
                byte[] chunk = new byte[chunkSize];
                fis.read(chunk, 0, chunkSize);

                // 创建小文件并写入数据
                File chunkFile = new File("chunk" + i + ".txt");
                FileOutputStream fos = new FileOutputStream(chunkFile);
                fos.write(chunk, 0, chunkSize);
                fos.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        fileSplit();
    }
}
